//
//  BaseInfoCell.m
//  HuaRun2
//
//  Created by admin on 17/8/29.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "BaseInfoCell.h"
#import "ImageLabView.h"
#import "Com_DetailModel.h"

@interface BaseInfoCell ()

@property (nonatomic, strong) UIView * backView;

//名字
@property (nonatomic, strong) UILabel * nameLab;
@property (nonatomic, strong) UIImageView * iconView;
@end

@implementation BaseInfoCell
#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = RGBA(249, 249, 249, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    [self.contentView addSubview:self.backView];

    [self.contactView addSubview:self.iconView];
    [self.contentView addSubview:self.nameLab];
    
    [self.contentView addSubview:self.noteView];
    [self.contentView addSubview:self.contactView];
    [self.contentView addSubview:self.meetingView];
    [self.contentView addSubview:self.giftView];
    
}

- (void)layoutInit {
    weakself(ws);
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(0);
        make.bottom.mas_equalTo(ws.contentView);
    }];

    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.left.mas_equalTo(ws.backView).offset(kMargin10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.iconView.mas_right).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
    }];
    
    [self.noteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.nameLab.mas_bottom).offset(kMargin10);
        make.left.mas_equalTo(ws.iconView).offset(0);
    }];
        
    [self.contactView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.noteView.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.noteView).offset(0);
    }];
    
    [self.meetingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.contactView.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.noteView).offset(0);
    }];
    
    [self.giftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.meetingView.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.meetingView).offset(0);
    }];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setDetailModel:(Com_DetailModel *)detailModel {
    _detailModel = detailModel;
    _nameLab.text = [NSString showSpaceStringWithStr: _detailModel.parentName];
    _noteView.infoStr = [NSString showSpaceStringWithStr: _detailModel.generalLine];
    _contactView.infoStr = [NSString showSpaceStringWithStr: _detailModel.fax];
    _meetingView.infoStr = [NSString showSpaceStringWithStr: _detailModel.email];
//    _meetingView.infoStr = @"781178325@qq.com";
    _giftView.infoStr = [NSString showSpaceStringWithStr: _detailModel.website];
    
}

#pragma mark - getter
- (UIImageView *)iconView {
    if (!_iconView) {
        self.iconView = [UIImageView new];
        _iconView.image = [UIImage imageNamed:@"公司-1"];
    }
    return _iconView;
}
    
- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLab.text = @"wwowoo";
    }
    return _nameLab;
}

- (ImageLabView *)noteView {
    if (!_noteView) {
        self.noteView = [ImageLabView new];
        _noteView.iconView.image = [UIImage imageNamed:@"电话_lianxiren"];
        _noteView.infoStr = @"电话";
        _noteView.eventType = EventTypeCall;
    }
    return _noteView;
}

- (ImageLabView *)contactView {
    if (!_contactView) {
        self.contactView = [ImageLabView new];
        //        _contactView.imageSize = CGSizeMake(25, 25);
        _contactView.iconView.image = [UIImage imageNamed:@"传真-1"];
        _contactView.infoStr = @"icon_fax";
        
    }
    return _contactView;
}

- (ImageLabView *)meetingView {
    if (!_meetingView) {
        self.meetingView = [ImageLabView new];
        //        _meetingView.imageSize = CGSizeMake(25, 25);
        _meetingView.iconView.image = [UIImage imageNamed:@"邮箱-1"];
        _meetingView.infoStr = @"icon_email";
        
    }
    return _meetingView;
}

- (ImageLabView *)giftView {
    if (!_giftView) {
        self.giftView = [ImageLabView new];
        //        _giftView.imageSize = CGSizeMake(25, 25);
        _giftView.iconView.image = [UIImage imageNamed:@"网址-1"];
        _giftView.infoStr = @"icon_url";
        _giftView.eventType = EventTypeUrl;
    }
    return _giftView;
}

- (UIView *)backView {
    if (!_backView) {
        self.backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}
@end
